home *** CD-ROM | disk | FTP | other *** search
/ CU Amiga Super CD-ROM 14 / CU Amiga Magazine's Super CD-ROM 14 (1997)(EMAP Images)(GB)(Track 1 of 3)[!][issue 1997-09].iso / CUCD / Programming / Asm_course / assembler course / MENU_WINDOW+LOAD.S < prev    next >
Encoding:
Text File  |  1992-04-27  |  3.6 KB  |  157 lines

  1.  
  2.     ; finally, this source will show the same menu as the other one,
  3.     ; but this one will EXECUTE a command when you type a selection.
  4.     ; see 'routine1' etc.
  5.  
  6. START:    movem.l    d0-a6,-(a7)            ; save all registers on stack
  7.  
  8. OPENDOSLIB:
  9.     move.l    $4,a6
  10.     move.l    #doslibname,a1
  11.     jsr    -408(a6)
  12.     move.l    d0,dosbase
  13.     beq.w    error
  14.  
  15. OPEN:    move.l    #filename,d1            ; open a window (see filename)
  16.     move.l    #1006,d2
  17.     move.l    dosbase,a6
  18.     jsr    -30(a6)
  19.     move.l    d0,filehandle
  20.     beq.w    error
  21.  
  22. WRITE:    move.l    filehandle,d1            ; handle of file (window)
  23.     move.l    #menutext,d2            ; address of text
  24.     move.l    #endofmenutext-menutext,d3    ; length of text
  25.     move.l    dosbase,a6
  26.     jsr    -48(a6)                ; 'Write'
  27.  
  28. READ:    ; read some text from this window (you must type something!)
  29.     ; the READ command in the doslib is used. It needs 3 parameters:
  30.  
  31.     move.l    filehandle,d1            ; again, d1 must contain the
  32.                         ; handle of our file (window)
  33.     move.l    #buffer,d2            ; d2 must contain the address
  34.                         ; of the buffer, where the
  35.                         ; text to be read will be 
  36.                         ; stored to.
  37.     move.l    #5,d3                ; d3=the amount of bytes to be
  38.                         ; read. (unless you type
  39.                         ; return earlier)
  40.     move.l    dosbase,a6
  41.     jsr    -42(a6)                ; call the 'read' command
  42.  
  43.  
  44. CHECK:    move.b    buffer,d0            ; check first character in the
  45.                         ; buffer:
  46.     cmp.b    #"1",d0
  47.     beq.s    routine1            ; switch to each routine
  48.  
  49.     cmp.b    #"2",d0                ; for the different possible
  50.     beq.s    routine2            ; menu-options
  51.  
  52.     cmp.b    #"3",d0
  53.     beq.s    routine3
  54.  
  55.     cmp.b    #"4",d0
  56.     beq.w    close                ; 4: end-of-program
  57.  
  58.     ; none of the possible characters were entered, so the user typed
  59.     ; something else: display an error message, using the WRITE command:
  60.  
  61.     move.l    filehandle,d1            ; handle of output-file
  62.     move.l    #errormessage,d2        ; address of the text
  63.     move.l    #endoferror-errormessage,d3    ; length of text
  64.     move.l    dosbase,a6
  65.     jsr    -48(a6)                ; 'Write'
  66.  
  67. DELAY:    ; now wait 1 second and re-display the menu
  68.  
  69.     move.l    #50,d1                ; time to delay (1 sec)
  70.     move.l    dosbase,a6
  71.     jsr    -198(a6)            ; 'delay'
  72.     
  73.     bra    WRITE                ; and goto 'WRITE'
  74.  
  75. *********
  76.  
  77. routine1:
  78.     move.l    #demoname1,d1            ; name of command to be
  79.                         ; executed
  80.     clr.l    d2                ; zero
  81.     clr.l    d3                ; zero
  82.     move.l    dosbase,a6
  83.     jsr    -222(a6)            ; call the 'EXECUTE' command
  84.     bra    DELAY
  85.  
  86. routine2:
  87.     move.l    #demoname2,d1            ; name of command to be
  88.                         ; executed
  89.     clr.l    d2                ; zero
  90.     clr.l    d3                ; zero
  91.     move.l    dosbase,a6
  92.     jsr    -222(a6)            ; call the 'EXECUTE' command
  93.     bra    DELAY
  94.     
  95. routine3:
  96.     move.l    #demoname2,d1            ; name of command to be
  97.                         ; executed
  98.     clr.l    d2                ; zero
  99.     clr.l    d3                ; zero
  100.     move.l    dosbase,a6
  101.     jsr    -222(a6)            ; call the 'EXECUTE' command
  102.     bra    DELAY
  103.  
  104. ***********
  105.  
  106. CLOSE:    ; now close the file, opened with the OPEN command. This will in this
  107.     ; case close the window.
  108.  
  109.     move.l    filehandle,d1            ; d1 must contain the file-
  110.                         ; handle.
  111.     move.l    dosbase,a6
  112.     jsr    -36(a6)                ; call the 'close' command.
  113.  
  114.  
  115. error:    movem.l    (a7)+,d0-a6            ; restore all registers
  116.     rts                    ; end of program
  117.  
  118. ***************************
  119.  
  120. ;; Here starts the DATA part. Make sure it is situated BEHIND the code-part
  121.  
  122.  
  123. doslibname:    dc.b    "dos.library",0
  124. filename:    dc.b    "con:100/50/440/180/ Simple Menu, made for Mike ",0
  125.  
  126.  
  127. menutext:    dc.b    27,"c"        ; 27,"c" clears the window
  128.         dc.b    10        ; 10 means 'return'
  129.         dc.b    10
  130.         dc.b    "  Please make a selection:",10
  131.         dc.b    "  ------------------------",10
  132.         dc.b    10
  133.         dc.b    10
  134.         dc.b    "  1. load demo 1",10
  135.         dc.b    "  2. load demo 2",10
  136.         dc.b    "  3. load demo 3",10
  137.         dc.b    "  4. exit",10
  138.         dc.b    10
  139.         dc.b    "  Your choice: ",0
  140. endofmenutext:
  141.  
  142. demoname1:    dc.b    "df0:demo1",0
  143. demoname2:    dc.b    "df0:demo2",0
  144. demoname3:    dc.b    "df0:demo3",0
  145.  
  146. errormessage:    dc.b    10,"Wrong selection ! Please try again !",0
  147. endoferror:
  148.  
  149. buffer:        blk.b    5,0    ; reserve 5 bytes to read some text
  150.  
  151.         even
  152.  
  153.  
  154. dosbase:    dc.l    0
  155. filehandle:    dc.l    0
  156.  
  157.